package com.zzj.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.zzj.bean.TabSupplier;
import com.zzj.service.TabSupplierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Map;

/**
 * <p>
 * InnoDB free: 8192 kB 前端控制器
 * </p>
 *
 * @author 花
 * @since 2022-03-04
 */
@Api
@CrossOrigin
@RestController
@RequestMapping("/supplier")
public class TabSupplierController {

    @Resource
    private TabSupplierService tabSupplierService;


    @ApiOperation("获得所有的")
    @GetMapping("findAll")
    public PageInfo<TabSupplier> findAll(@RequestParam(defaultValue = "1") Integer pageNum,
                                         @RequestParam(defaultValue = "5") Integer pageSize){

        return  tabSupplierService.findAll(pageNum,pageSize);

    }

    @ApiOperation("添加供货记录")
    @PostMapping("add")
    public boolean add(@RequestBody TabSupplier tabSupplier,@RequestParam(defaultValue = "0") String sustatus){
        System.out.println(tabSupplier);
        tabSupplier.setSustatus(sustatus);
        tabSupplier.setSutime(LocalDateTime.now());
        return tabSupplierService.save(tabSupplier);
    }


    @PostMapping("fuzzyQuery")
    @ApiOperation("模糊查询")
    public Page<TabSupplier> fuzzyQuery(@RequestBody Map<String,String> map){
        QueryWrapper wrapper=new QueryWrapper();
        String key = map.get("key");
        String value = map.get("value");
        wrapper.like(key,value);
        Page<TabSupplier> page = new Page<>();
        return tabSupplierService.page(page,wrapper);
    }


}

